//
//  AddMemberViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15/9/27.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "AddMemberViewController.h"
#import "HZAreaPickerView.h"
#import "GuideListTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface AddMemberViewController ()<HZAreaPickerDelegate>
{
    NSString * memberGradeCodeStr;
    NSString *provinceStr;
    NSString *cityStr;
    NSString *regionStr;
    NSString *addressStr;
    NSString *guideCodeStr;
    NSString *openIdStr;
    NSString *qrCodeStr;
    NSString *sexStr;
    BOOL isOpened;
    BOOL memberGradeIsOpen;
    NSMutableArray *memberGradeNameArray;
    NSMutableArray *memberGradeCodeArray;
    NSMutableArray *featureCodeArray;
    NSMutableArray *featureNameArray;
    NSMutableArray *selectFeatureCodeArray;
    NSMutableArray *guideNameArray;
    NSMutableArray *guideCodeArray;
    
     NSMutableArray *memberDetailFeaturesNameArray;
}
@property (strong, nonatomic) NSString *areaValue, *cityValue;
@property (strong, nonatomic) HZAreaPickerView *locatePicker;
@end

@implementation AddMemberViewController
@synthesize areaValue=_areaValue, cityValue=_cityValue;
@synthesize locatePicker=_locatePicker;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    if (_timer!=nil) {
        [_timer invalidate];
        _timer=nil;
    }
   
    provinceStr=@"";
    cityStr=@"";
    regionStr=@"";
    addressStr=@"";
    guideCodeStr=@"";
    openIdStr=@"";
    memberGradeCodeStr=@"";
    
    isOpened=NO;
    memberGradeIsOpen=NO;
    memberGradeNameArray=[NSMutableArray array];
    memberGradeCodeArray=[NSMutableArray array];
    
    
    featureCodeArray=[NSMutableArray array];
    featureNameArray=[NSMutableArray array];
    selectFeatureCodeArray=[NSMutableArray array];
    memberDetailFeaturesNameArray=[NSMutableArray array];
    
    
    guideNameArray=[NSMutableArray array];
    guideCodeArray=[NSMutableArray array];
    
    
    _addGuideListViewContainer.hidden=YES;
    CGRect frame=_addGuideListViewContainer.frame;
    frame.size.height=1;
    [_addGuideListViewContainer setFrame:frame];
    
    CGRect viewFrame1=_addAreaContainer.frame;
    viewFrame1.origin.y=768;
    _addAreaContainer.frame=viewFrame1;
    
    CGRect viewFrame=_memberBirthViewContainer.frame;
    viewFrame.origin.y=768;
    _memberBirthViewContainer.frame=viewFrame;
    
     _addScanViewContainer.hidden=YES;
    
    qrCodeStr=@"";
    
    _switch1.backgroundColor = [UIColor clearColor];
    _switch1.onTintColor = [UIColor colorWithRed:45.0f/255.0f green:158.0f/255.0f blue:237.0f/255.0f alpha:1.0f];
    _switch1.onText = @"男";
    
    _switch1.on=YES;
    sexStr=@"男";
    _switch1.offText = @"女";
    _switch1.tintColor = [UIColor colorWithRed:253.0f/255.0f green:129.0f/255.0f blue:182.0f/255.0f alpha:1.0f];
    [_switch1 addTarget:self action:@selector(handleSwitchEvent:) forControlEvents:UIControlEventValueChanged];
    // [_addMemberViewContainer addSubview:switch1];
    
    [_addSelectGuideBtn addTarget:self action:@selector(selectGuideBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [_addMemberAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_addMemberAlphaView addTarget:self action:@selector(addMemberAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    _addBarCodeBtn.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _addBarCodeBtn.layer.borderWidth= 1.0f;
    _addBarCodeBtn.layer.cornerRadius=3;
    
    _addRemarkTextView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _addRemarkTextView.layer.borderWidth= 1.0f;
    _addRemarkTextView.layer.cornerRadius=3;
    
    _selectMemberButton.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _selectMemberButton.layer.borderWidth= 1.0f;
    _selectMemberButton.layer.cornerRadius=3;
    if (_docNumStr.length>0) {
        _selectMemberButton.hidden=NO;
    }
    else
    {
        _selectMemberButton.hidden=YES;
    }
   
    //[_scanButton setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
         
         [self requestTags];
    _addGuideListArrowImage.hidden=NO;
    [_addSelectGuideBtn setUserInteractionEnabled:YES];

    if (_userCodeStr.length>0) {
        _addGuideListArrowImage.hidden=YES;
        [_addSelectGuideBtn setUserInteractionEnabled:NO];
        
        [self requestMemberDetail:_userCodeStr];
    }
    
    

}
-(IBAction)selectMemberClick:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(commonSelectMemberBtnClick)]) {
        [self.delegate commonSelectMemberBtnClick];
    }
    

}
-(void)selectGuideBtnClick
{
    
    if (isOpened) {
        _addGuideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            CGRect frame=_addGuideListViewContainer.frame;
            
            frame.size.height=1;
            [_addGuideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpened=NO;
        }];
        
    }
    else
    {
        [self requestGuideList];
        _addGuideListViewContainer.hidden=NO;
        [UIView animateWithDuration:0.5 animations:^{
           
            CGRect frame=_addGuideListViewContainer.frame;
            
            frame.size.height=657;
            [_addGuideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpened=YES;
        }];
        
    }
    
}
-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"Guide/GuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [guideCodeArray removeAllObjects];
                    [guideNameArray removeAllObjects];
                   NSMutableArray *mGuidesArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [guideCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserCode"]];
                        [guideNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    [_addGuideListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                        [Global loginViewController:self noteStr:requestResultStr];
                        //   [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(IBAction)barCodeBtnClick:(id)sender
{
    for (UIView *v in _addMemberMainView.subviews) {
        if (v.tag==90000) {
            [v removeFromSuperview];
            
        }
        
    }
 
    
    CGRect viewFrame0=_addScanViewContainer.frame;
    viewFrame0.origin.y=65;
    _addScanViewContainer.frame=viewFrame0;
    CGRect viewFrame1=_addAreaContainer.frame;
    viewFrame1.origin.y=768;
    _addAreaContainer.frame=viewFrame1;
    
    //    CGRect viewFrame=_birthViewContainer.frame;
    //    viewFrame.origin.y=768;
    //    _birthViewContainer.frame=viewFrame;
    [_addNameTextField resignFirstResponder];
    [_addAddressTextField resignFirstResponder];
    [_addPhoneTextField resignFirstResponder];
    _addScanViewContainer.hidden=NO;
    [self requestBarCodeImage];
    //   NSLog(@"33333");
    
}
-(void)requestBarCodeImage
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestBarCodeData:@"Common/CreateWxQrCode" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            [Global hideProgressHUDInternal:self.view];
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    //   [Global hideProgressHUDInternal:self.view];
                    //   NSLog(@"severdatdddddd111=%@",severDataDict.dataDict);
                    [_barcodeImageView setImageWithURL:[NSURL URLWithString:[severDataDict.dataDict objectForKey:@"QrCodeUrl"]]];
                    qrCodeStr=[severDataDict.dataDict objectForKey:@"QrCode"];
                    
                    if (_timer==nil) {
                        
                        _timer = [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(requestBarCodeInfo) userInfo:nil repeats:YES];
                    }
                }
                else
                {
                    // [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                        [Global loginViewController:self noteStr:requestResultStr];
                        //  [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(void)requestBarCodeInfo
{
    if ([Global getLoginToken].length>0) {
        // [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:qrCodeStr forKey:@"QrCode"];
        
        // NSLog(@"rrrrr==%@",params);
        [HttpRequest requestBarCodeData:@"Common/GetQrCodeInf" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            //  NSLog(@"222222222==%@",severDataDict.dataDict);
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    
                    if (_timer!=nil) {
                        [_timer invalidate];
                        _timer=nil;
                    }
                    
                    //  [Global hideProgressHUDInternal:self.view];

                    if ([[severDataDict.dataDict objectForKey:@"Subscribe"] integerValue]==0) {
                        _addScanViewContainer.hidden=YES;
                        _addBarcodeTextField.text=[severDataDict.dataDict objectForKey:@"NickName"];
                        _addAreaTextField.text=[NSString stringWithFormat:@"%@%@%@",[severDataDict.dataDict objectForKey:@"Country"],[severDataDict.dataDict objectForKey:@"Province"],[severDataDict.dataDict objectForKey:@"City"]];
                         _addAddressTextField.text=[NSString stringWithFormat:@"%@%@%@",[severDataDict.dataDict objectForKey:@"Country"],[severDataDict.dataDict objectForKey:@"Province"],[severDataDict.dataDict objectForKey:@"City"]];
                        sexStr=[severDataDict.dataDict objectForKey:@"Sex"];
                        openIdStr=[severDataDict.dataDict objectForKey:@"OpenID"];
                        if ([sexStr isEqualToString:@"男"]) {
                            _switch1.onText = @"男";
                            
                            _switch1.on=YES;
                        }
                        
                        else
                        {
                            _switch1.offText = @"女";
                        }
                        //  _areaTextField.text=[NSString stringWithFormat:@"%@%@%@",[severDataDict.dataDict objectForKey:@"Country"],[severDataDict.dataDict objectForKey:@"Province"],[severDataDict.dataDict objectForKey:@"City"]];
                        
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    //  NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    // [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global loginViewController:self noteStr:requestResultStr];
                        // [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
//
-(IBAction)scanCancelBtnClick:(id)sender
{
    // [self stopReading];
    if (_timer!=nil) {
        [_timer invalidate];
        _timer=nil;
    }
    [HttpRequest cancelRequest];
    _addScanViewContainer.hidden=YES;
}

-(void)requestMemberDetail:(NSString *)userCode
{
    
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:userCode forKey:@"UserCode"];
        [HttpRequest requestData:@"Guide/FindMemberInf" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            //  NSLog(@"serrr==%@",severDataDict.dataDict);
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    // NSLog(@"345==%@",[severDataDict.dataDict  objectForKey:@"Sex"]);
                   NSString * detailSexStr=[severDataDict.dataDict  objectForKey:@"Sex"];
                    if ([detailSexStr isEqualToString:@"男"]) {
                        _switch1.on=YES;
                    }
                    else if ([detailSexStr isEqualToString:@"女"])
                        _switch1.on=NO;
                    
                    _addNameTextField.text=[severDataDict.dataDict objectForKey:@"UserName"];
                    _memberGradeTextField.text=[severDataDict.dataDict objectForKey:@"Grade"];
                    
                    provinceStr =[severDataDict.dataDict objectForKey:@"ProvinceName"];
                    cityStr=[severDataDict.dataDict objectForKey:@"CityName"];
                    regionStr=[severDataDict.dataDict objectForKey:@"RegionName"] ;
                    _addAreaTextField.text=[NSString stringWithFormat:@"%@%@%@",[severDataDict.dataDict objectForKey:@"ProvinceName"],[severDataDict.dataDict objectForKey:@"CityName"],[severDataDict.dataDict objectForKey:@"RegionName"]];
                    _addAddressTextField.text=[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"Address"]];
                   
                    _addPhoneTextField.text=[severDataDict.dataDict objectForKey:@"Phone"];
                    
                    
                    _addRemarkTextView.text=[severDataDict.dataDict objectForKey:@"Memo"];
                    //[Global resizeTextView:_detail_remarkView contentStr: _detail_remarkView.text];
                    if (_addRemarkTextView.text.length>0) {
                        _addTextviewLabel.hidden=YES;
                        _addTextviewImage.hidden=YES;
                    }
                    else
                    {
                        _addTextviewLabel.hidden=NO;
                        _addTextviewImage.hidden=NO;
                    }
                    _addGuideNameLabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
                    
                    [Global resizeForLable:_addGuideNameLabel WithText:_addGuideNameLabel.text parentView:self.view];
                    CGRect frameK=_addGuideNameLabel.frame;
                    frameK.origin.x=_addGuideListArrowImage.frame.origin.x-frameK.size.width-5;
                    _addGuideNameLabel.frame=frameK;
                    
                    NSString *birthStr=[severDataDict.dataDict objectForKey:@"BirthDate"];
                    if (birthStr.length>0) {
                        _memberBirthTextField.text=birthStr;
                    }
                    else
                    {
                        _memberBirthTextField.text=@"";
                    }
                    //[self resizeLabel:_detail_birthLabel];
                  
                    
                    NSString *nickStr=[severDataDict.dataDict objectForKey:@"NickName"];
                    if (nickStr.length>0) {
                        _addBarcodeTextField.text=nickStr;
                    }
                    else
                    {
                        _addBarcodeTextField.text=@"";
                    }
                    
                    
                    NSMutableArray * mMemberDetailFeaturesArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    [memberDetailFeaturesNameArray removeAllObjects];
                    //[memberDetailFeaturesNameArray removeAllObjects];
                    for (int i=0; i<mMemberDetailFeaturesArray.count; i++) {
                        [memberDetailFeaturesNameArray addObject:[[mMemberDetailFeaturesArray objectAtIndex:i] objectForKey:@"FeatureName"]];
                        [selectFeatureCodeArray addObject:[[mMemberDetailFeaturesArray objectAtIndex:i] objectForKey:@"FeatureCode"]];
                    }
                    [self setTagView];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    //                    if (timer!=nil) {
                    //                        [timer invalidate];
                    //                        timer=nil;
                    //                    }
                    //                    UIViewController *controller=[[GlobalViewController alloc]init];
                    //                    [self.navigationController pushViewController:controller animated:YES];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                        [Global loginViewController:self noteStr:requestResultStr];
                        //  [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(void)addMemberAlphaViewClick
{
    if (_timer!=nil) {
        [_timer invalidate];
        _timer=nil;
    }
    [HttpRequest cancelRequest];
    _addScanViewContainer.hidden=YES;
    
    if (self.view!=nil) {
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
    
}
}
- (void)handleSwitchEvent:(ZJSwitch *)sender
{
    if (sender.on==1) {
        sexStr=@"男";
    }
    else
    {
        sexStr=@"女";
    }
    //  NSLog(@"%d",sender.on);
}

-(void)requestTags
{
    // NSLog(@"##");
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"/Guide/FeatureList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [featureCodeArray removeAllObjects];
                    [featureNameArray removeAllObjects];
                  NSMutableArray * mFeaturesArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<mFeaturesArray.count; i++) {
                        [featureCodeArray addObject:[[mFeaturesArray objectAtIndex:i] objectForKey:@"FeatureCode"]];
                        [featureNameArray addObject:[[mFeaturesArray objectAtIndex:i] objectForKey:@"FeatureName"]];
                    }
                    //   NSLog(@"featureNameArray=%@",featureNameArray);
                    [self setTagView];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                        [Global loginViewController:self noteStr:requestResultStr];
                        //  [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}
-(void)setTagView
{
    for (int i=0; i<featureNameArray.count; i++) {
        
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        CGRect rect=button.frame;
        rect.size.height=32;
        rect.size.width=80;
        rect.origin.x=17+90*(i%6);
        rect.origin.y=17+46*(i/6);
        button.frame=rect;
        button.tag=i;
        [button setBackgroundColor:[UIColor clearColor]];
        button.layer.borderWidth=1;
        button.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1.0f] CGColor];
        button.layer.cornerRadius=16;
        button.titleLabel.font = [UIFont systemFontOfSize: 15.0];
        [button setTitleColor:[UIColor colorWithRed:100.0f/255.0f green:100.0f/255.0f blue:100.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        // [button setBackgroundColor:[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1.0f]];
        [button setTitle:[featureNameArray objectAtIndex:i] forState:UIControlStateNormal];
        // [button setTitleColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        if (memberDetailFeaturesNameArray.count>0) {
            for (int j=0; j<memberDetailFeaturesNameArray.count; j++) {
                if ([[featureNameArray objectAtIndex:i] isEqualToString:[memberDetailFeaturesNameArray objectAtIndex:j]]) {
                    // button.layer.borderColor=[[UIColor colorWithRed:252.0f/255.0f green:165.0f/255.0f blue:0.0f/255.0f alpha:1] CGColor];
                    button.layer.borderWidth= 1.0f;
                    [button setBackgroundColor:[UIColor colorWithRed:254.0f/255.0f green:249.0f/255.0f blue:228.0f/255.0f alpha:1.0f]];
                    //  button.layer.borderWidth=1;
                    button.layer.borderColor=[[UIColor colorWithRed:226.0f/255.0f green:208.0f/255.0f blue:166.0f/255.0f alpha:1.0f] CGColor];
                    [button setTitleColor:[UIColor colorWithRed:209.0f/255.0f green:174.0f/255.0f blue:80.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                    
                }
            }
        }

        [button addTarget:self action:@selector(tagButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_addTagView addSubview:button];
    }
}
-(void)tagButtonClick:(UIButton *)sender
{
    [sender setBackgroundColor:[UIColor colorWithRed:254.0f/255.0f green:249.0f/255.0f blue:228.0f/255.0f alpha:1.0f]];
    sender.layer.borderWidth=1;
    sender.layer.borderColor=[[UIColor colorWithRed:226.0f/255.0f green:208.0f/255.0f blue:166.0f/255.0f alpha:1.0f] CGColor];
    [sender setTitleColor:[UIColor colorWithRed:209.0f/255.0f green:174.0f/255.0f blue:80.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
    
    if (![selectFeatureCodeArray containsObject:[featureCodeArray objectAtIndex:sender.tag]]) {
        [selectFeatureCodeArray addObject:[featureCodeArray objectAtIndex:sender.tag]];
        sender.layer.borderColor=[[UIColor colorWithRed:226.0f/255.0f green:208.0f/255.0f blue:166.0f/255.0f alpha:1.0f] CGColor];
        sender.layer.borderWidth= 1.0f;
        [sender setTitleColor:[UIColor colorWithRed:209.0f/255.0f green:174.0f/255.0f blue:80.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];    }
    else
    {
        [selectFeatureCodeArray removeObject:[featureCodeArray objectAtIndex:sender.tag]];
        sender.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1.0f] CGColor];
        sender.layer.borderWidth= 1.0f;
        [sender setBackgroundColor:[UIColor clearColor]];
        [sender setTitleColor:[UIColor colorWithRed:100.0f/255.0f green:100.0f/255.0f blue:100.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
        
    }
    // NSLog(@"selectCodeArray====%@",selectCodeArray);
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if ([textField isEqual:_addAddressTextField])
    {
        [UIView animateWithDuration:0.2f animations:^
         {
             CGRect viewFrame=_addMemberMainView.frame;
             viewFrame.origin.y=-60;
             _addMemberMainView.frame=viewFrame;
         }completion:^(BOOL finished) {
             
         }];
        return YES;
        
    }
    
    else if ([textField isEqual:_addAreaTextField]) {
        [_addNameTextField resignFirstResponder];
        [_addAddressTextField resignFirstResponder];
        [_addPhoneTextField resignFirstResponder];
        
        [UIView animateWithDuration:0.5f animations:^
         {
             CGRect viewFrame=_addAreaContainer.frame;
             viewFrame.origin.y=65;
             _addAreaContainer.frame=viewFrame;
         }completion:^(BOOL finished) {
             
             
         }];
        [self cancelLocatePicker];
        self.locatePicker = [[HZAreaPickerView alloc] initWithStyle:HZAreaPickerWithStateAndCityAndDistrict delegate:self];
        [self.locatePicker showInView:_addAreaView];
        return NO;
    }
    else if (textField==_memberGradeTextField)
    {
        [_addNameTextField resignFirstResponder];
        [_addAddressTextField resignFirstResponder];
        [_addPhoneTextField resignFirstResponder];
        if (!memberGradeIsOpen) {
            [self requestMemberGrade];
        }
        else
        {
            for (UIView *v in _addMemberMainView.subviews) {
                if (v.tag==90000) {
                    [v removeFromSuperview];
                    
                }
                
            }
            
        }
        memberGradeIsOpen=!memberGradeIsOpen;
        
        
        return NO;
    }
    else if ([textField isEqual:_memberBirthTextField])
    {
       
        [_addNameTextField resignFirstResponder];
        [_addAddressTextField resignFirstResponder];
        [_addPhoneTextField resignFirstResponder];
        [UIView animateWithDuration:0.5f animations:^
         {
             CGRect viewFrame=_memberBirthViewContainer.frame;
             viewFrame.origin.y=65;
             _memberBirthViewContainer.frame=viewFrame;
         }completion:^(BOOL finished) {
             
             
         }];
        return NO;
        
    }
    
    return YES;
}
- (BOOL)textFieldDidEndEditing:(UITextField *)textField
{
    if ([textField isEqual:_addAddressTextField])
    {
        [UIView animateWithDuration:0.5f animations:^
         {
             CGRect viewFrame=_addMemberMainView.frame;
             viewFrame.origin.y=0;
             _addMemberMainView.frame=viewFrame;
         }completion:^(BOOL finished) {
             
         }];
        
        
    }
    
    return  YES;
}

-(void)requestMemberGrade
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:@"MemberLevel" forKey:@"KeyWord"];
        //   NSLog(@"params====%@",params);
        [HttpRequest requestData:@"Common/GetDictList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            // NSLog(@"resultttttt=%@",severDataDict.dataDict);
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    //  NSLog(@"resultttttt=%@",severDataDict.dataDict);
                    [memberGradeCodeArray removeAllObjects];
                    [memberGradeNameArray removeAllObjects];
                    NSMutableArray *dataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    
                    for (int i=0; i<dataLineArray.count; i++) {
                        [memberGradeNameArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"Name"]];
                        [memberGradeCodeArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"Code"]];
                        
                    }
                    //  NSLog(@"memberGradeCodeArray ==%@",memberGradeCodeArray);
                    for (UIView *v in _addMemberMainView.subviews) {
                        if (v.tag==90000) {
                            [v removeFromSuperview];
                            
                        }
                        
                    }
                    
                    [self setMemberGradeView];
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                        [Global loginViewController:self noteStr:requestResultStr];
                        // [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(void)setMemberGradeView
{
    UIView *memberGradeView=[[UIView alloc] initWithFrame:CGRectMake(0, _memberGradeLineLabel.frame.origin.y+_memberGradeLineLabel.frame.size.height+1, 620, 459)];
    [memberGradeView setBackgroundColor:[UIColor whiteColor]];
    memberGradeView.tag=90000;
    [_addMemberMainView addSubview:memberGradeView];
    
    for (int i=0; i<memberGradeCodeArray.count; i++) {
        
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        CGRect rect=button.frame;
        rect.size.height=50;
        rect.size.width=620;
        rect.origin.x=0;
        rect.origin.y=10+50*i;
        button.frame=rect;
        button.tag=i;
        [button setBackgroundColor:[UIColor whiteColor]];
        [button setTitle:[memberGradeNameArray objectAtIndex:i] forState:UIControlStateNormal];
        
        [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(selectMemberGradeBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        
        UILabel *textLabel=[[UILabel alloc] initWithFrame:CGRectMake(38, 20,400, 20)];
        [textLabel setText:[memberGradeNameArray objectAtIndex:i]];
        [textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
        [textLabel setBackgroundColor:[UIColor clearColor]];
        [button addSubview:textLabel];
        
        UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(20,49, 630, 1)];
        
        [lineLabel setBackgroundColor:[UIColor clearColor]];
        [lineLabel setText:@"－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－"];
        [lineLabel setTextColor:[UIColor colorWithRed:241.0f/255.0f green:241.0f/255.0f blue:241.0f/255.0f alpha:1.0f]];
        
        NSInteger index=[memberGradeNameArray indexOfObject:_memberGradeTextField.text];
        if (index !=NSNotFound) {
            if (i==index) {
                
                
                UIImageView *selectImageview=[[UIImageView alloc] initWithFrame:CGRectMake(555, 11, 30, 30)];
                [selectImageview setImage:[UIImage imageNamed:@"xuanzhong_.png"]];
                [button addSubview:selectImageview];
            }
        }
        
        [button addSubview:lineLabel];
        [memberGradeView addSubview:button];
    }
}
-(void)selectMemberGradeBtn:(UIButton *)sender
{
    _memberGradeTextField.text=sender.titleLabel.text;
    memberGradeIsOpen=NO;
    memberGradeCodeStr=[memberGradeCodeArray objectAtIndex:sender.tag];
    UIImageView *selectImageview=[[UIImageView alloc] initWithFrame:CGRectMake(555, 11, 30, 30)];
    [selectImageview setImage:[UIImage imageNamed:@"xuanzhong_.png"]];
    [sender addSubview:selectImageview];
    
    for (UIView *v in _addMemberMainView.subviews) {
        if (v.tag==90000) {
            [v removeFromSuperview];
            
        }
        
    }
    
}
-(void)cancelLocatePicker
{
    [self.locatePicker cancelPicker];
    self.locatePicker.delegate = nil;
    self.locatePicker = nil;
}
#pragma mark - HZAreaPicker delegate
-(void)sureBtnClick
{
    CGRect viewFrame=_addAreaContainer.frame;
    viewFrame.origin.y=768;
    _addAreaContainer.frame=viewFrame;
    
    self.areaValue = [NSString stringWithFormat:@"%@ %@ %@", self.locatePicker.locate.state, self.locatePicker.locate.city, self.locatePicker.locate.district];
    _addAreaTextField.text=self.areaValue ;
    provinceStr=[NSString stringWithFormat:@"%@",self.locatePicker.locate.state];
    cityStr=[NSString stringWithFormat:@"%@",self.locatePicker.locate.city];
    regionStr=[NSString stringWithFormat:@"%@",self.locatePicker.locate.district];
    //  NSLog(@"regionstr===%@",regionStr);
    // NSString *address=[NSString stringWithFormat:@"%@%@%@", self.locatePicker.locate.state, self.locatePicker.locate.city, self.locatePicker.locate.district];
    //_addressTextField.text=[NSString stringWithFormat:@"%@",address];
    
    
    [self cancelLocatePicker];
    
}
-(void)pickerDidChaneStatus:(HZAreaPickerView *)picker
{
    if (picker.pickerStyle == HZAreaPickerWithStateAndCityAndDistrict) {
        self.areaValue = [NSString stringWithFormat:@"%@ %@ %@", picker.locate.state, picker.locate.city, picker.locate.district];
        _addAreaTextField.text=self.areaValue ;
        provinceStr=[NSString stringWithFormat:@"%@",picker.locate.state];
        cityStr=[NSString stringWithFormat:@"%@",picker.locate.city];
        regionStr=[NSString stringWithFormat:@"%@",picker.locate.district];
        //  NSLog(@"regionstr===%@",regionStr);
        //  NSString *address=[NSString stringWithFormat:@"%@%@%@", picker.locate.state, picker.locate.city, picker.locate.district];
        //_addressTextField.text=[NSString stringWithFormat:@"%@",address];
    }
}


-(IBAction)oneDatePickerValueChanged:(UIDatePicker *)sender
{
    NSDate *selectedDate =[sender date];
    //NSLog(@"curDate is %@" ,selectedDate);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //修改时区为东8区
    
    NSString *destDateString =@"";
   
        
        [dateFormatter setDateFormat:@"MM-dd"];
        destDateString = [dateFormatter stringFromDate:selectedDate];
        _memberBirthTextField.text=destDateString;
        
   
    
    // NSLog(@"destDateString is %@" ,destDateString);
}
-(IBAction)birthViewConfirmClick:(id)sender
{
    
    //NSLog(@"curDate is %@" ,selectedDate);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //修改时区为东8区
    
    NSString *destDateString =@"";
   
        NSDate *selectedDate =[_memberBirthDatePicker date];
        [UIView animateWithDuration:0.5f animations:^
         {
             CGRect viewFrame=_memberBirthViewContainer.frame;
             viewFrame.origin.y=768;
             _memberBirthViewContainer.frame=viewFrame;
         }completion:^(BOOL finished) {
             
             
         }];
        
        
        [dateFormatter setDateFormat:@"MM-dd"];
        destDateString = [dateFormatter stringFromDate:selectedDate];
        _memberBirthTextField.text=destDateString;
   
    
    
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if ([textView isEqual:_addRemarkTextView]) {
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_addMemberMainView.frame;
            viewFrame.origin.y=-(_addRemarkTextView.frame.origin.y+_addRemarkTextView.frame.size.height+398-768);
            _addMemberMainView.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];
        
    }
    
    
    return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect viewFrame=_addMemberMainView.frame;
        viewFrame.origin.y=0;
        _addMemberMainView.frame=viewFrame;
    } completion:^(BOOL finished){
        
    }];
    
    
    
}
- (void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length == 0) {
        _addTextviewImage.hidden=NO;
        _addTextviewLabel.hidden=NO;
        
    }
    else
    {
        _addTextviewImage.hidden=YES;
        _addTextviewLabel.hidden=YES;
        
    }
}


-(IBAction)confirmAddMemberClick:(id)sender
{
    if (![self validateMobile:_addPhoneTextField.text])
    {
        [Global showTextHudSub:@"请输入正确的电话的号码" view:self.view];
    }
    else
    {
        if ([Global getLoginToken].length>0) {
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            NSMutableArray *mDocumentLine=[NSMutableArray array];
            for (int i=0; i<selectFeatureCodeArray.count; i++) {
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                NSString *codeStr = [selectFeatureCodeArray objectAtIndex:i];
                [dic setValue:codeStr forKey:@"FeatureCode"];
                
                [mDocumentLine addObject:dic];
            }
            NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
            [params setObject:[Global getLoginToken] forKey:@"Token"];
            [params setObject:_addOrEditStr forKey:@"EditType"];
            [params setObject:_addNameTextField.text forKey:@"UserName"];
            [params setObject:openIdStr forKey:@"OpenID"];
            //[params setObject:@"" forKey:@"UserCode"];
            
            // [params setObject:@"" forKey:@"UserCode"];
            [params setObject:provinceStr forKey:@"ProvinceName"];
            [params setObject:cityStr forKey:@"CityName"];
            [params setObject:regionStr forKey:@"RegionName"];
            [params setObject:_addAddressTextField.text forKey:@"Address"];
             [params setObject:_docNumStr forKey:@"DocNum"];
            
            [params setObject:_memberBirthTextField.text forKey:@"BirthDate"];
            
            [params setObject:_addPhoneTextField.text forKey:@"Phone"];
            //  [params setObject:_phoneTextField.text forKey:@"Phone"];
            [params setObject:sexStr forKey:@"Sex"];
            [params setObject:guideCodeStr forKey:@"GuideCode"];
            [params setObject:memberGradeCodeStr forKey:@"GradeCode"];
            [params setObject:_addBarcodeTextField.text forKey:@"NickName"];
            //  [params setObject:@"" forKey:@"UserCode"];
            [params setObject:mDocumentLine forKey:@"DataLine"];
            [params setObject:_addRemarkTextView.text forKey:@"Memo"];
            if ([_addOrEditStr isEqualToString:@"U"]) {
                [params setObject:_userCodeStr forKey:@"UserCode"];
            }
            //NSLog(@"MemberPARAM===%@",params);
            [HttpRequest requestData:@"Guide/EditMember" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        //   NSLog(@"severDataDict.dataDict===%@",severDataDict.dataDict);
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        if (self.view!=nil) {
                            [self.view removeFromSuperview];
                            [self removeFromParentViewController];
                            
                        }

                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        NSString *nameStr=[severDataDict.dataDict objectForKey:@"MemberName"];
                        NSString *phoneStr=[severDataDict.dataDict objectForKey:@"Phone"];
                        NSString *memberCodeStr=[severDataDict.dataDict objectForKey:@"MemberCode"];
                        NSString *gradeStr=[severDataDict.dataDict objectForKey:@"Grade"];
                        NSString *sexStr1=[severDataDict.dataDict objectForKey:@"Sex"];
                         NSString * integralStr =[NSString stringWithFormat:@"%ld",[[severDataDict.dataDict objectForKey:@"Integral"] integerValue]];
                        if ([self.delegate respondsToSelector:@selector(addOrEditMemberSuccess:memberGradeString:memberNameString:memberPhoneString:memberSexString:memberIntegralString:)]) {
                            [self.delegate addOrEditMemberSuccess:memberCodeStr memberGradeString:gradeStr memberNameString:nameStr memberPhoneString:phoneStr memberSexString:sexStr1 memberIntegralString:integralStr];
                        }

                        
                    }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        //  [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        //                    if (timer!=nil) {
                        //                        [timer invalidate];
                        //                        timer=nil;
                        //                    }
                        //                    UIViewController *controller=[[GlobalViewController alloc]init];
                        //                    [self.navigationController pushViewController:controller animated:YES];
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                            if (_timer!=nil) {
                                [_timer invalidate];
                                _timer=nil;
                            }
                            [Global loginViewController:self noteStr:requestResultStr];
                            // [Global loginViewController:self];
                        }
                        
                    }
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
            }];
            
        }
    }
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   return guideCodeArray.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
       static NSString * const  GuideListIdentifier = @"GuideListCellIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: GuideListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        //        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
        //        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (guideNameArray.count>0) {
            cell.guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_addGuideListTableView) {
        guideCodeStr=[guideCodeArray objectAtIndex:indexPath.row];
        
        _addGuideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
          
            CGRect frame=_addGuideListViewContainer.frame;
            
            frame.size.height=1;
            [_addGuideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpened=NO;
        }];
        _addGuideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        
        [Global resizeForLable:_addGuideNameLabel WithText:_addGuideNameLabel.text parentView:self.view];
        CGRect frameK=_addGuideNameLabel.frame;
        frameK.origin.x=_addGuideListArrowImage.frame.origin.x-frameK.size.width-5;
        _addGuideNameLabel.frame=frameK;

    }
}

- (BOOL)validateMobile:(NSString *)mobileNum
{
    /**
     * 手机号码
     * 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     * 联通：130,131,132,152,155,156,185,186
     * 电信：133,1349,153,180,189
     */
    NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|7[678]|8[025-9])\\d{8}$";
    /**
     10         * 中国移动：China Mobile
     11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     12         */
    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
    /**
     15         * 中国联通：China Unicom
     16         * 130,131,132,152,155,156,185,186
     17         */
    NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
    /**
     20         * 中国电信：China Telecom
     21         * 133,1349,153,180,189
     22         */
    NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
    
    NSString *others=@"^1((4[57]|7[0]))\\d{8}$";
    /**
     25         * 大陆地区固话及小灵通
     26         * 区号：010,020,021,022,023,024,025,027,028,029
     27         * 号码：七位或八位
     28         */
    // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    NSPredicate *regextestothers = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", others];
    
    if (([regextestmobile evaluateWithObject:mobileNum] == YES)
        || ([regextestcm evaluateWithObject:mobileNum] == YES)
        || ([regextestct evaluateWithObject:mobileNum] == YES)
        || ([regextestcu evaluateWithObject:mobileNum] == YES)||([regextestothers evaluateWithObject:mobileNum] == YES))
    {
        return YES;
    }
    else
    {
        return NO;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
